package com.mail.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.mail.common.DataResult;
import com.mail.dto.EmailConfigDto;
import com.mail.service.EmailConfigService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/email/config")
public class EmailConfigController {
    @Resource
    private EmailConfigService emailConfigService;

    /**
     * 添加邮件配置
     */
    @PostMapping("/addEmailConfig")
    public DataResult addEmailConfig(EmailConfigDto emailConfigDto){

        return emailConfigService.addEmailConfig(emailConfigDto);
    }

    /**
     * 修改邮件配置
     */
    @PutMapping("/updateEmailConfig")
    public DataResult updateEmailConfig(@RequestParam Map<String,Object> map){
        String id = (String) map.get("id");
        if (id.length() == 0) {
            return DataResult.error("请输入id！");
        }
        return emailConfigService.updateEmailConfig(map);
    }

    /**
     * 删除邮件配置
     */
    @DeleteMapping("/deleteEmailConfig/{id}")
    public DataResult deleteEmailConfig(@PathVariable long id){
        return emailConfigService.deleteEmailConfig(id);
    }

    /**
     查询某个用户下的邮件配置
     */
    @GetMapping("/queryEmailConfigPersonal")
    public DataResult queryEmailConfigPersonal(@RequestParam Map<String,Object> map){
        String page=(String) map.get("page");
        String limit=(String) map.get("limit");
        String id=(String) map.get("id");
        if(!StringUtils.isNotBlank(page) || !StringUtils.isNotBlank(limit) ||!StringUtils.isNotBlank(id)){
            return DataResult.error("不能为空！");
        }
        return emailConfigService.queryEmailConfigPersonal(map);
    }
}
